package com.dell.chen.dao.impl;

import com.dell.chen.dao.FlowerDao;
import com.dell.chen.pojo.Flowers;

import java.util.List;

/**
 * @author ：ChenwithIU
 * @date ：Created in 2020/11/27 11:11
 */
public class FlowerDaoImpl extends BaseDao implements FlowerDao {
    @Override
    public int addFlowers(Flowers flowers) {
        String sql = "insert into f_flowers(`name`,`sort_id`,`img_path`,`material`,`pack`,`price`,`slogan`) values(?,?,?,?,?,?,?)";
        return update(sql,flowers.getName(),flowers.getSort_id(),flowers.getImg_path(),flowers.getMaterial(),flowers.getPack(),flowers.getPrice(),flowers.getSlogan());
    }

    @Override
    public int deleteById(Integer id) {
        String sql = "delete from f_flowers where id = ?";
        return update(sql,id);
    }

    @Override
    public int update(Flowers flowers) {
        String sql = "update f_flowers set `name`=?,`sort_id`=?,`img_path`=?,`material`=?,`pack`=?,`price`=?,`slogan`=? where id = ?";
        return update(sql,flowers.getName(),flowers.getSort_id(),flowers.getImg_path(),flowers.getMaterial(),flowers.getPack(),flowers.getPrice(),flowers.getSlogan(),flowers.getId());
    }

    @Override
    public Flowers queryById(Integer id) {
        String sql = "select `id`,`name`,`sort_id` ,`img_path`,`material`,`pack`,`price`,`slogan` from f_flowers where id = ?";
        return queryForOne(Flowers.class,sql,id);
    }

    @Override
    public List<Flowers> queryFlowers() {
        String sql = "select `id`,`name`,`sort_id` ,`img_path` ,`material`,`pack`,`price`,`slogan` from f_flowers";
        return queryForList(Flowers.class,sql);
    }

    @Override
    public List<Flowers> queryForPageItems(int begin, int pageSize) {
        String sql = "select `id` , `name` , `sort_id` , `img_path` , `material` , `pack` , `price`,`slogan`  from f_flowers limit ?,?";
        return queryForList(Flowers.class,sql,begin,pageSize);
    }

    @Override
    public Integer queryForPageTotalCount() {
        String sql = "select count(*) from t_book";
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }

    @Override
    public Integer queryForPageTotalCountByPrice(int min, int max) {
        String sql = "select count(*) from t_book where price between ? and ?";
        Number count = (Number) queryForSingleValue(sql,min,max);
        return count.intValue();
    }

    @Override
    public List<Flowers> queryForPageItemsByPrice(int begin, int pageSize, int min, int max) {
        String sql = "select `id` , `name` , `sort_id` , `img_path` , `material` , `pack` , `price`,`slogan`,from f_flowers where price between ? and ? order by price limit ?,?";
        return queryForList(Flowers.class,sql,min,max,begin,pageSize);
    }
}
